package StringDemo.CompareString;
import java.util.Scanner;

public class Compare {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String st1 = "abc";
        String st2 = "abc";
        String st3 = new String("abc");
        String st4 = new String("Abc");
        //此表达式值为true，因为st1指向的地址和st2相同
        System.out.println(st1 == st2);
        //new String会在堆区开辟新地址，所以它们指向的地址不相同
        System.out.println(st1 == st3);
        //同上
        System.out.println(st3 == st4);
        //使用equals可以对比指向空间存储的数据
        System.out.println(st1.equals(st3));
        //equalsIgnoreCase无视大小写
        System.out.println(st3.equalsIgnoreCase(st4));
        String st5 = sc.next();
        //next方法创建的变量本质也是new出来的，所以要用equals或equalIgnoreCase比较
        System.out.println(st1 == st5);
        System.out.println(st1.equals(st5));

    }
}
